
#if defined(WIN32)
#include "fm_guid.h"

#include <stdio.h>
#include <guiddef.h>
#include <windows.h>

#define Uppercase_FORMAT "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"
#define Lowercase_FORMAT "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"

BOOL GenGUID(char* buf, BOOL bCaps)
{
  GUID guid;
  
  if(NULL == buf){
	return FALSE;
  }
  
  if (FAILED(CoCreateGuid(&guid))) {
    return FALSE;
  }
  

  snprintf(buf, GUID_LEN, bCaps ? Uppercase_FORMAT : Lowercase_FORMAT,
    guid.Data1, guid.Data2, guid.Data3,
    guid.Data4[0], guid.Data4[1], guid.Data4[2],
    guid.Data4[3], guid.Data4[4], guid.Data4[5],
    guid.Data4[6], guid.Data4[7]);
  
  buf[GUID_LEN - 1] = 0;
  
  return TRUE;
}
#endif

